
<template>
    <div v-if="detailsVisible" >
         <div>
             <el-row style="margin: 10px 20px 10px 10px;">
                <span class="demonstration">年份：</span>
                <el-date-picker v-model="year" type="year" placeholder="" value-format="yyyy" @change="changeyaer"></el-date-picker>
                <div style="float: right">
                    <el-button  size="mini"    @click="serchfileA" >查询</el-button>
                    <el-button  size="mini"  @click="addfile" v-show="showAdd">新增</el-button>
                </div>
            </el-row>
            <el-table :data="recoderfilesTrue"  border  :empty-text="showemptytext" >
                <el-table-column  width="65" label="标识" :show-overflow-tooltip='true' align="center">
                    <template slot-scope="scope">
                        <img class="default-image" :src="$store.state.images.wujiaoxing" style="width：45px;height:45px;"> 
                    </template> 
                </el-table-column>
                <el-table-column type="index" width="60" label="序号"  :index="indexbf" :show-overflow-tooltip='true'  align="center"></el-table-column>
                <el-table-column width="570" label="参训人员" :show-overflow-tooltip='true' align="center" >
                    <template slot-scope="scope">
                        <a target="_blank" >{{scope.row.persons}}</a>
                        <!-- <el-input type="textarea" autosize placeholder="" v-model="scope.row.persons" :disabled="true"></el-input> -->
                    </template> 
                </el-table-column>
                <el-table-column prop="pxdw" width="220" label="培训单位"   :show-overflow-tooltip='true'  align="center"></el-table-column>
                <el-table-column prop="pxtime" width="120" label="培训时间" :show-overflow-tooltip='true'  align="center"></el-table-column>
                <el-table-column prop="pxnr" width="590" label="培训内容" :show-overflow-tooltip='true'  align="center"></el-table-column>
            </el-table>
            <pagination @changed="showDataTrue" :recoder="recoderfiles"> </pagination>
        </div>
        <dypxadd ref='dypxadd' v-on:editResult="serchfileA"></dypxadd>
    </div>
</template>
<script>
    import {mapActions} from 'vuex';
    export default {
        data: () => ({
            detailsVisible:true,
            showAdd:false,//显示添加的按钮,  //只有党支部才可以显示添加
            recoderfiles:[], //获取到的文件
            recoderfilesTrue:[],//真正在表格里面显示的 由于分页等原因
            offset:0,
            year:'2015',
            default_emptytext:"请左侧选择年份并查询",
            showemptytext:'',
        }),
        mounted() {
            if(this.GetUser()==false){
                this.$router.push("/");
            }
            this.year=(new Date()).getFullYear()+''
        },
        watch: {},
        components: {
            dypxadd: function(resolve) {require(["./dypxadd.vue"], resolve);},
        },
        methods: {
            ...mapActions(['GetUser','GetZbById','GetActiveDwId_DzbId']),
            changeyaer(year){
                this.serchfileA();
            },
            showDataTrue(showrecoders,offset){
                this.recoderfilesTrue=showrecoders;
                this.offset=offset;
            },
            indexbf(index){return index+this.offset+1;},
            serchfileA(){
                this.recoderfilesTrue=[];
                let _this=this;
                let postdata={
                    type:"selectdypx",
                    split:JSON.stringify({
                        dwid:this.$store.state.Dw_DzbID.dwid,
                        dzbid:this.$store.state.Dw_DzbID.dzbid,
                        year:this.year,
                    })
                }
                this.$Common.AjaxPost(postdata,true)
                .then(function(e){
                    if(e.dypxs.length==0){
                        _this.showemptytext='没有找到记录';
                        setTimeout(() => {
                            _this.showemptytext=_this.default_emptytext;
                        }, 1000);
                    }
                    else{
                        _this.recoderfiles=e.dypxs; 
                    }
                }).catch(function(reason) {
                    console.log('catch:', reason);
                });
            },
            addfile()
            {
                this.$refs.dypxadd.$data.dialogVisible = true;
                this.$refs.dypxadd.$data.rowdata.year = this.year;
            },
        }
    }
</script>